﻿using System;
using System.Data;
using RpcHelper;
using SqlExecHelper;

using Wedonek.RpcStore.Service.Model;

namespace Wedonek.RpcStore.Service.DAL
{
        internal class RpcMerConfigDAL : SqlBasicClass
        {
                public RpcMerConfigDAL () : base ("RpcMerConfig")
                {

                }
                public bool CheckIsExists (long rpcMerId, long sysTypeId)
                {
                        return base.CheckIsExists (new ISqlWhere[]{
                                new SqlWhere("RpcMerId", SqlDbType.BigInt){Value=rpcMerId},
                                new SqlWhere("SystemTypeId", SqlDbType.BigInt) { Value = sysTypeId }
                        });
                }
                public RpcMerConfig[] GetConfigs (long rpcMerId)
                {
                        return base.Get<long, RpcMerConfig> ("RpcMerId", rpcMerId);
                }
                public RpcMerConfig GetConfig (Guid id)
                {
                        return this.GetRow<Guid, RpcMerConfig> ("Id", id);
                }

                public void Add (RpcMerConfig add)
                {
                        base.Insert (add);
                }

                public void Set (Guid id, SetMerConfig config)
                {
                        if (!this.Update (config, "Id", id))
                        {
                                throw new ErrorException ("rpc.mer.config.set.error");
                        }
                }
                public void Drop (Guid id)
                {
                        if (!this.Drop ("Id", id))
                        {
                                throw new ErrorException ("rpc.mer.config.drop.error");
                        }
                }
        }
}
